import React from "react"
import styles from './refreshIcon.less'
import refreshIcon from '../../assets/image/refresh.svg'
import { throttle } from '../../utils/utils'

export default class RefreshIcon extends React.Component {

    doSpin = ()=>{
        const refresh = this.refresh
        let originAngle = refresh.style.transform.replace(/[^0-9]/ig, '');
        if (originAngle) {
            originAngle = parseInt(originAngle, 10);
        } else {
            originAngle = 0;
        }
        refresh.style.transform = 'rotate(' + (originAngle + 360) + 'deg)';
    }

    handleClick = () => {
        this.doSpin()
        this.props.click()
    }

    render() {
        const { content } = this.props
        return (
            <p className={styles.refresh_p} onClick={this.handleClick}>
                <img
                    className={styles.refreshIcon}
                    src={refreshIcon}
                    alt=""
                    ref={(refresh) => { this.refresh = refresh }}
                /> <span> {content} </span>
            </p>
        )
    }
}
